import 'package:flutter/material.dart';
import 'package:ivc/routers/application.dart';
import 'package:ivc/icons/IVCIcons.dart';

class FactoryOwnerPage extends StatefulWidget {
  @override
  FactoryOwnerPageState createState() => new FactoryOwnerPageState();
}

class FactoryOwnerPageState extends State<FactoryOwnerPage> {
  List<Map<String, Object>> _indexCardDataList = new List();
  List<Map<String, Object>> _recommends = new List();
  final List<String> notifyMsgs = [
    "第三玩具车间 确定一个新订单 左滑可删除",
    "三湘银行提供4000万融资租赁服务",
    "一笔50000元维修订单完成",
    "关于鼓励区内企业使用ERP服务的通知",
    "揭阳工信与三湘银行达成战略合作协议",
    "米国取消塑胶玩具15%关税",
    "企业上链申请等待审批",
  ];
  @override
  void initState() {
    super.initState();
    _indexCardDataList.add({"title": "采购", "icon": "b2b_procurement", "route": "/b2b/portal"});
    _indexCardDataList.add({"title": "租赁", "icon": "lending", "route": "/lending/portal"});
    _indexCardDataList.add({"title": "维修", "icon": "mr", "route": "/mr/portal"});
    _indexCardDataList.add({"title": "技改", "icon": "tech", "route": "/tech/portal"});
    _indexCardDataList.add({"title": "物联", "icon": "iiot", "route": "/iiot/portal"});
    _indexCardDataList.add({"title": "验厂", "icon": "check", "route": "/factory/check_request"});
    _indexCardDataList.add({"title": "接单", "icon": "order", "route": "/b2b/asset_procurement"});
    _indexCardDataList.add({"title": "生产", "icon": "produce", "route": "/b2b/asset_procurement"});
    _indexCardDataList.add({"title": "设计", "icon": "logistics", "route": "/b2b/asset_procurement"});
    _indexCardDataList.add({"title": "培训", "icon": "mr", "route": "/mr/portal"});
    _indexCardDataList.add({"title": "招工", "icon": "tech", "route": "/tech/portal"});
    _indexCardDataList.add({"title": "巡厂", "icon": "iiot", "route": "/iiot/portal"});
    _indexCardDataList.add({"title": "软件", "icon": "check", "route": "/factory/check_request"});
    _indexCardDataList.add({"title": "分包", "icon": "order", "route": "/b2b/asset_procurement"});

    _recommends.add({"title": "风机技术改造服务", "image": "https://cn.bing.com/th?id=OIP.g9mTZnM2FVPBHIODCEvW9QHaFj&pid=Api&rs=1"});
    _recommends.add({"title": "全国招募压路机试驾", "image": "https://www.sanygroup.com/d/file/media/zhanhui/2017-02-28/e0fa79c6314492fc2f95ee7c2b55b333.jpg"});
    _recommends.add({"title": "三一压得快系列SSR220AC-8压路机", "image": "https://product.sanygroup.com/road/v4/img/cp3.jpg"});
    _recommends.add({"title": "压路机现场教学,报名从优", "image": "http://www.sanygroup.com/d/file/anli/2017-04-19/13189e3d03474987006de69361202eb9.jpg"});
    _recommends.add({"title": "金融服务", "image": "https://www.sanygroup.com/31/img/jr5.jpg"});
    _recommends.add({"title": "SY75二手小型挖掘机六成新", "image": "http://used.sanygroup.com/images/201608/source_img/161_P_1470359542560.jpg"});
    _recommends.add({"title": "纯正滤芯", "image": "http://img.qipeiren.com/UploadFile/UserProPic/2019/6/5/416ea4157c98a2fd8b10-220.jpg"});
    _recommends.add({"title": "SCP100H叉车", "image": "https://product.sanygroup.com/images/201809/1537233930595592736.jpg"});
    _recommends.add({"title": "风机技术改造服务", "image": "https://cn.bing.com/th?id=OIP.g9mTZnM2FVPBHIODCEvW9QHaFj&pid=Api&rs=1"});
    _recommends.add({"title": "全国招募压路机试驾", "image": "https://www.sanygroup.com/d/file/media/zhanhui/2017-02-28/e0fa79c6314492fc2f95ee7c2b55b333.jpg"});
    _recommends.add({"title": "三一压得快系列SSR220AC-8压路机", "image": "https://product.sanygroup.com/road/v4/img/cp3.jpg"});
    _recommends.add({"title": "压路机现场教学,报名从优", "image": "http://www.sanygroup.com/d/file/anli/2017-04-19/13189e3d03474987006de69361202eb9.jpg"});
    _recommends.add({"title": "金融服务", "image": "https://www.sanygroup.com/31/img/jr5.jpg"});
    _recommends.add({"title": "SY75二手小型挖掘机六成新", "image": "http://used.sanygroup.com/images/201608/source_img/161_P_1470359542560.jpg"});
    _recommends.add({"title": "纯正滤芯", "image": "http://img.qipeiren.com/UploadFile/UserProPic/2019/6/5/416ea4157c98a2fd8b10-220.jpg"});
    _recommends.add({"title": "SCP100H叉车", "image": "https://product.sanygroup.com/images/201809/1537233930595592736.jpg"});
    _recommends.add({"title": "风机技术改造服务", "image": "https://cn.bing.com/th?id=OIP.g9mTZnM2FVPBHIODCEvW9QHaFj&pid=Api&rs=1"});
    _recommends.add({"title": "全国招募压路机试驾", "image": "https://www.sanygroup.com/d/file/media/zhanhui/2017-02-28/e0fa79c6314492fc2f95ee7c2b55b333.jpg"});
    _recommends.add({"title": "三一压得快系列SSR220AC-8压路机", "image": "https://product.sanygroup.com/road/v4/img/cp3.jpg"});
    _recommends.add({"title": "压路机现场教学,报名从优", "image": "http://www.sanygroup.com/d/file/anli/2017-04-19/13189e3d03474987006de69361202eb9.jpg"});
    _recommends.add({"title": "金融服务", "image": "https://www.sanygroup.com/31/img/jr5.jpg"});
    _recommends.add({"title": "SY75二手小型挖掘机六成新", "image": "http://used.sanygroup.com/images/201608/source_img/161_P_1470359542560.jpg"});
    _recommends.add({"title": "纯正滤芯", "image": "http://img.qipeiren.com/UploadFile/UserProPic/2019/6/5/416ea4157c98a2fd8b10-220.jpg"});
    _recommends.add({"title": "SCP100H叉车", "image": "https://product.sanygroup.com/images/201809/1537233930595592736.jpg"});
    }

  @override
  Widget build(BuildContext context) {
    //super.build(context);
    return CustomScrollView(
      shrinkWrap: true,
      slivers: <Widget>[
        SliverAppBar(
          /*  leading: FadeInImage.assetNetwork(
            placeholder: "assets/images/house.png",
            image: 'https://picsum.photos/250?image=9',
          ),
*/
          flexibleSpace: FlexibleSpaceBar(
              //可以展开区域，通常是一个FlexibleSpaceBar
              centerTitle: true,
              title: Text(""),
              background: Image.network(
                "http://www.rootcloud.com/ueditor/php/upload/image/20190617/1560760426107121.jpg",
                fit: BoxFit.cover,
              )),
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.shopping_cart),
              tooltip: 'Open shopping cart',
              onPressed: () {
                Application.router.navigateTo(context, "/placeorder");
              },
            ),
          ],
          primary: true, //是否预留高度
          forceElevated: true,
          automaticallyImplyLeading: true,
          snap: false, //与floating结合使用
          expandedHeight: 100.0, //展开高度
          floating: false, //是否随着滑动隐藏标题
          pinned: true, //是否固定在顶部
          backgroundColor: Colors.lightGreen,
        ),
        SliverPadding(
          padding: EdgeInsets.all(10),
          sliver:
        SliverGrid(
          gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: 50.0,
            mainAxisSpacing: 10.0,
            crossAxisSpacing: 10.0,
            childAspectRatio: 1.0,
          ),
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                decoration: new BoxDecoration(
                    color: Colors.green, //new Color.fromRGBO(255, 0, 0, 0.0),
                    borderRadius: new BorderRadius.all(const  Radius.circular(10.0)),
                ),
                child: GestureDetector(
                  child: Column(children: <Widget>[
//                    Icon(Icons.call,size: 12.0 ),
                    Icon(IVCIcons.getIcon(_indexCardDataList[index]["icon"]), size: 18.0, color: Colors.white),
                    Text(_indexCardDataList[index]["title"],
                        style: new TextStyle(
                          color: Colors.white,
                          fontSize: 12.0,
                        )),
                  ]),
                  onTap: () {
                    Application.router.navigateTo(
                        context, _indexCardDataList[index]["route"]);
                  },
                ),
              );
            },

            childCount: _indexCardDataList.length,
          ),
        )),
        SliverToBoxAdapter(
            child:
              Row(
                children: <Widget>[
                  Image.asset("assets/images/rcrobot.gif", height: 20),
                  Text("小树根据您的企业情况, 向您推荐以下产品及服务", style: new TextStyle(
                    color: Colors.black54,
                    fontSize: 12.0,
                  )),
                ],
              )
        ),

        SliverPadding(
            padding: EdgeInsets.all(10),
            sliver:
            SliverGrid(
              gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
                maxCrossAxisExtent: 300.0,
                mainAxisSpacing: 10.0,
                crossAxisSpacing: 10.0,
                childAspectRatio: 1.0,
              ),
              delegate: SliverChildBuilderDelegate(
                    (BuildContext context, int index) {
                  return Container(
                    alignment: Alignment.center,
                    child: GestureDetector(
                      child: Column(children: <Widget>[
                        Expanded(
                          flex: 1,
                          child: Image.network(_recommends[index]["image"]),
                        ),
                        Text(_recommends[index]["title"],
                            style: new TextStyle(
                              color: Colors.black,
                              fontSize: 12.0,
                            )),
                      ]),
                      onTap: () {
                        Application.router.navigateTo(
                            context, _indexCardDataList[index]["route"]);
                      },
                    ),
                  );
                },

                childCount: _indexCardDataList.length,
              ),
            )),
        SliverFixedExtentList(
          itemExtent: 50.0,
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                color: Colors.lightBlue[100 * (index % 2)],
                child: Text(notifyMsgs[index]),
              );
            },
            childCount: notifyMsgs.length,
          ),
        ),
      ],
    );
  }
}
